import { http } from '../http/axios';
import { ENDPOINTS } from '../constants/endpoints';
import type {
  Member,
  CreateMemberRequest,
  UpdateMemberRequest,
  MemberQueryParams
} from '../types/member';

export const memberService = {
  // 获取人员列表
  getMembers: async (params?: MemberQueryParams): Promise<Member[]> => {
    const response = await http.get(ENDPOINTS.MEMBER.LIST, { params });
    return response.data;
  },

  // 获取单个人员
  getMember: async (id: number): Promise<Member> => {
    const response = await http.get(ENDPOINTS.MEMBER.DETAIL(id));
    return response.data;
  },

  // 创建人员
  createMember: async (data: CreateMemberRequest): Promise<Member> => {
    const response = await http.post(ENDPOINTS.MEMBER.CREATE, data);
    return response.data;
  },

  // 更新人员
  updateMember: async (id: number, data: UpdateMemberRequest): Promise<Member> => {
    const response = await http.put(ENDPOINTS.MEMBER.UPDATE(id), data);
    return response.data;
  },

  // 删除人员
  deleteMember: async (id: number): Promise<void> => {
    await http.delete(ENDPOINTS.MEMBER.DELETE(id));
  },
};